package com.wk.jetpackdemo.entities

import android.arch.persistence.room.ColumnInfo
import android.arch.persistence.room.Embedded
import android.arch.persistence.room.Entity
import android.arch.persistence.room.PrimaryKey
import com.google.gson.annotations.SerializedName
import java.io.Serializable

/**
 * 页面描述：文章
 *
 * Created by ditclear on 2017/9/26.
 */
@Entity(tableName = "articles")
class Article : Serializable {

    var title: String? = null
    @PrimaryKey
    @ColumnInfo(name = "articleid")
    var id: Int = 0
    @Embedded
    var user: User? = null
    var content: String? = null
    var readme: String? = null
    @SerializedName("describe")
    var description: String? = null
    var click: Int = 0
    var channel: Int = 0
    var comments: Int = 0
    var stow: Int = 0
    var upvote: Int = 0
    var downvote: Int = 0
    var url: String? = null
    var pubDate: String? = null
    var thumbnail: String? = null
    override fun toString(): String {
        return "Article(title=$title, id=$id, user=$user, content=$content, readme=$readme, description=$description, click=$click, channel=$channel, comments=$comments, stow=$stow, upvote=$upvote, downvote=$downvote, url=$url, pubDate=$pubDate, thumbnail=$thumbnail)"
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as Article

        if (title != other.title) return false
        if (id != other.id) return false
        if (user != other.user) return false
        if (content != other.content) return false
        if (readme != other.readme) return false
        if (description != other.description) return false
        if (click != other.click) return false
        if (channel != other.channel) return false
        if (comments != other.comments) return false
        if (stow != other.stow) return false
        if (upvote != other.upvote) return false
        if (downvote != other.downvote) return false
        if (url != other.url) return false
        if (pubDate != other.pubDate) return false
        if (thumbnail != other.thumbnail) return false

        return true
    }

    override fun hashCode(): Int {
        var result = title?.hashCode() ?: 0
        result = 31 * result + id
        result = 31 * result + (user?.hashCode() ?: 0)
        result = 31 * result + (content?.hashCode() ?: 0)
        result = 31 * result + (readme?.hashCode() ?: 0)
        result = 31 * result + (description?.hashCode() ?: 0)
        result = 31 * result + click
        result = 31 * result + channel
        result = 31 * result + comments
        result = 31 * result + stow
        result = 31 * result + upvote
        result = 31 * result + downvote
        result = 31 * result + (url?.hashCode() ?: 0)
        result = 31 * result + (pubDate?.hashCode() ?: 0)
        result = 31 * result + (thumbnail?.hashCode() ?: 0)
        return result
    }


}
